package com.morontestandroid;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class FifthLevel extends Activity implements android.view.View.OnClickListener {
	
	ImageView secondSmallestImage,secondBiggestImage, img1;
	boolean secondBiggestClicked, firstObject;
	Chronometer mChronometer;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fifth_level);
		mChronometer = (Chronometer) findViewById(R.id.level5ChrmId);
		img1 = (ImageView) findViewById(R.id.img11);
		secondSmallestImage = (ImageView) findViewById(R.id.secondSmallestId);
		secondBiggestImage = (ImageView) findViewById(R.id.secondBiggestId);
		//backgr = (ImageView) findViewById(R.id.level5BackgId);
		
	    mChronometer.setBase(getTime()); 
		mChronometer.start();
		
		img1.setOnClickListener(this);
		secondSmallestImage.setOnClickListener(this);
		secondBiggestImage.setOnClickListener(this);
		//backgr.setOnClickListener(this);
		secondBiggestImage.bringToFront();
		firstObject = true;
		secondBiggestClicked = false;
		
	       

		       TextView txt = (TextView) findViewById(R.id.textq);  
		       Typeface font = Typeface.createFromAsset(getAssets(), "testtext.ttf");  
		        txt.setTypeface(font);
	}

	public long getTime() {
		  Bundle extras = getIntent().getExtras();
		  long time = extras.getLong("time");
		  return time;
		 
	}
	
	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		if (view.getId() == R.id.img11) {
			startActivity(new Intent(this, FailActivity.class));
		}
		
		else if(view.getId() == R.id.secondBiggestId && firstObject) {
			secondBiggestClicked = true;
			firstObject = false;
			secondBiggestImage.setVisibility(View.GONE);
			secondSmallestImage.bringToFront();
		}
		
		else if (view.getId() == R.id.secondSmallestId && secondBiggestClicked) {
			secondBiggestClicked = false;
			secondSmallestImage.setVisibility(View.GONE);
			int activityID = 1;
			Intent intent;
			intent = new Intent().setClass(this, CheckPoint.class);
			intent.putExtra("time", getThisBase());
			startActivityForResult(intent, activityID);
			
		}
		else {
			startActivity(new Intent(this, FailActivity.class));
		}
	}

	public long getThisBase(){
		  return mChronometer.getBase();
		 
	}
	public void onBackPressed() {
		// do something on back.
		startActivity(new Intent(this, MenyActivity.class));
		return;
		}
	
}

// startActivity(new Intent(this, FirstLevel.class));

